<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/generic/SugarWidgets/SugarWidgetSubPanelTopButtonQuickCreate.php');

class SugarWidgetSubPanelTopCreateDocumentButton extends SugarWidgetSubPanelTopButtonQuickCreate
{

	function __construct(){
		$title = 'LBL_NEW_BUTTON_TITLE';
                $accesskey = 'LBL_NEW_BUTTON_KEY';
                $value = 'LBL_NEW_BUTTON_LABEL';
                $module = 'Documents';
		return parent::__construct($module, $title, $accesskey, $value);
	}

	function display($defines, $additionalFormFields = null)
	{
		$this->acl = 'edit';

                if($_REQUEST['module']=='Tasks')
		{
			$task = new Task();
			$task->retrieve($_REQUEST['record']);
			if(!empty($task))
			{
		     		$additionalFormFields['relate_id'] = $task->deliverable_id;
		     		$additionalFormFields['return_relationship'] = 'edanz_Deliverables';
			}
			
		}
		switch($defines['focus']->module_dir){
			case 'edanz_Editor':
				$additionalFormFields['category_id'] = 'EditorRelated';
				break;
			case 'Tasks':
				$additionalFormFields['task_type'] = $defines['focus']->type;
				
				switch($defines['focus']->type){
					case 'FishTestReceived':
						$additionalFormFields['category_id'] = 'EditorRelated';
						$additionalFormFields['template_type'] = 'FishTest';
						break;
					case '2ndTestReceived':
						$additionalFormFields['category_id'] = 'EditorRelated';
						$additionalFormFields['template_type'] = '2ndRecruitmentTest';
						break;
					case 'ContractedFreelanceEditorAgreement':
						$additionalFormFields['category_id'] = 'EditorRelated';
						$additionalFormFields['template_type'] = 'Contract';
						break;
					case 'ConfidentialityAgreement':
						$additionalFormFields['category_id'] = 'EditorRelated';
						$additionalFormFields['template_type'] = 'ConfidentialityAgreement';
						break;
					case 'JapaneseCVTranslation':
					case 'ChineseCVTranslation':
						$additionalFormFields['category_id'] = 'EditorRelated';
						$additionalFormFields['template_type'] = 'MiniCV';
						break;
					default:
						$additionalFormFields['category_id'] = 'EditorRelated';
				}

				break;
		}
		return parent::display($defines, $additionalFormFields);
	}
	
}
?>
